package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.CheckItem;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CheckItemDao {

    /**
     * 根据条件查询
     * @param queryString
     * @return
     */
    @Select("<script>select * from t_checkitem <if test=\"queryString!=null and queryString!=''\">where code=#{queryString} or name=#{queryString}</if></script>")
    Page<CheckItem> selectByCondition(@Param("queryString") String queryString);

    /**
     * 添加信息
     * @param checkItem
     */
    @Insert("insert into t_checkitem(id,code,name,sex,age,price,type,attention,remark)values(#{id},#{code},#{name},#{sex},#{age},#{price},#{type},#{attention},#{remark})")
    void add(CheckItem checkItem);

    /**
     * 修改信息
     */
    @Update("update t_checkitem set code=#{code},name=#{name},sex=#{sex},age=#{age},price=#{price},type=#{type},attention=#{attention},remark=#{remark} where id=#{id}")
    void edit(CheckItem checkItem);

    /**
     * 删除信息
     * @param id
     */
    @Delete("delete from t_checkitem where id=#{id}")
    void deleteById(Integer id);

    /**
     * 根据id查询,是否关联其他表
     * @param id
     * @return
     */
    @Select("select count(*) from t_checkgroup_checkitem where checkitem_id=#{id}")
    long findCountByCheckItemId(Integer id);

    @Select("select * from t_checkitem")
    List<CheckItem> findAll();
    //====================================================

    //移动端查询所有检查项
    @Select("select * from t_checkitem where id in (select checkitem_id from t_checkgroup_checkitem where checkgroup_id=#{CheckGroupId})")
    List<CheckItem> findCheckItemByCheckGroup(Integer CheckGroupId);
}
